package com.hnjd.headline.utils;

/**
 * 全局统一返回结果类
 */
public class Result {
    // 返回码
    private Integer code;
    // 返回消息
    private String message;
    // 返回数据
    private Object data;

    // 无参构造方法
    public Result(){}

    // 全参构造方法
    public Result(int code, String message, Object data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    // 枚举响应状态构造方法
    public Result(ResultCodeEnum resultCodeEnum, Object data) {
        this(resultCodeEnum.getCode(), resultCodeEnum.getMessage(), data);
    }

    // 成功响应工厂
    public static Result ok(Object data) {
        return new Result(ResultCodeEnum.SUCCESS, data);
    }

    // 成功响应(无数据)
    public static Result ok() {
        return ok(null);
    }

    // 工厂方法
    public static Result build(int code, String message, Object data) {
        return new Result(code, message, data);
    }

    // 枚举响应状态工厂
    public static Result build(ResultCodeEnum resultCodeEnum, Object data) {
        return new Result(resultCodeEnum, data);
    }

    // 枚举响应状态工厂(无数据)
    public static Result build(ResultCodeEnum resultCodeEnum) {
        return build(resultCodeEnum, null);
    }

    // 连续赋值方法
    public Result code(int code) {
        this.code = code;
        return this;
    }

    public Result message(String message) {
        this.message = message;
        return this;
    }

    public Result data(Object data) {
        this.data = data;
        return this;
    }

    // Getter && Setter
    public Integer getCode() {
        return this.code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMessage() {
        return this.message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Object getData() {
        return this.data;
    }

    public void setData(Object data) {
        this.data = data;
    }
    
}